home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 2 / Gekikoh Dennoh Club Vol. 2 (Japan).7z / Gekikoh Dennoh Club Vol. 2 (Japan) (Track 01).bin / tools / cd2pcmt / source.lzh / music_bios.c < prev    next >
Text File  |  1997-10-01  |  5KB  |  181 lines

  1. #include "cd2pcm.h"
  2. #include "extern.h"
  3.  
  4. /* 
  5.   低レベルルーチン (CD-ROMを直接操作するルーチン集。各々のドライブに
  6.             依存するルーチン。)
  7. */
  8.  
  9. /* ストップコマンドを送る */
  10. int StpDsk( void )
  11. {
  12.     unsigned char    buf[256];            /* ローカルワーク */
  13.  
  14.     memset( buf, 0x00, 10 );
  15.     buf[0] = 0x4b;                    /* scsi2 Pause/Resume Command */
  16.     return( scsi_cmd( 10, buf, 0, buf ) );
  17.  
  18. }
  19.  
  20. /* Resume コマンドを送る */
  21. int Resume( void )
  22. {
  23.     unsigned char    buf[256];            /* ローカルワーク */
  24.  
  25.     memset( buf, 0x00, 10 );
  26.     buf[0] = 0x4b;                    /* scsi2 Pause/Resume Command */
  27.     buf[8] = 0x01;                    /* Resume Command */
  28.     return( scsi_cmd( 10, buf, 0, buf ) );
  29.  
  30. }
  31.  
  32. /* 演奏状態を調べる */
  33. int ChkPly( PLYINF *plyinf )
  34. {
  35.     unsigned char    buf2[256];            /* ローカルワーク */
  36.     int rc;
  37.     
  38.     if ( ReadSub( buf2 ) == 0 )
  39.     {
  40.         plyinf->fg       = buf2[1];        /* 状態 */
  41.         plyinf->track_no = buf2[6];        /* 曲番号 */
  42.         plyinf->time     = buf2[13] * 0x10000 + buf2[14] * 0x100 + buf2[15];
  43.         plyinf->address  = buf2[9]  * 0x10000 + buf2[10] * 0x100 + buf2[11];
  44.         rc = 0;
  45. #ifdef DEBUG1
  46.         printf(" Index = %d\n",buf[7]);
  47. #endif
  48.     }
  49.     else
  50.         rc = -1;
  51.  
  52.     return(rc);
  53. }
  54.  
  55. /* 演奏させる */
  56. int PlyDsk( int start , int stop )
  57. {
  58.     unsigned char    buf[256];            /* ローカルワーク */
  59.     int    dmymin,dmymax;                /* ダミー変数 */
  60.     int    rc;
  61.  
  62.     if ( stop == -1 )
  63.     {
  64.         /* 最後まで演奏する */
  65.         if ( RedTOC( &stop, &dmymin, &dmymax ) != 0 )
  66.             return(-1);
  67.         stop = bin2time( time2bin( stop ) -1 );
  68.     }
  69.  
  70.     /* Play Audio MSF  Command */
  71.     memset( buf, 0x00, 10 );
  72.     buf[0] = 0x47;                /* Play Audio MSF Command */
  73.     buf[3] = ( start / 0x10000 ) & 0xff;
  74.     buf[4] = ( start / 0x100 ) & 0xff;
  75.     buf[5] = start & 0xff;
  76.     buf[6] = ( stop / 0x10000 ) & 0xff;
  77.     buf[7] = ( stop / 0x100 ) & 0xff;
  78.     buf[8] = stop & 0xff;
  79.     if ( (rc=scsi_cmd( 10, buf, 0, buf ))!=0 )
  80.         if ( (rc=scsi_cmd( 10, buf, 0, buf ))!=0 )
  81.             rc=scsi_cmd( 10, buf, 0, buf );
  82.     return( rc );
  83. }
  84.  
  85. /* Read Sub-Channel */
  86. int ReadSub( unsigned char *buf2 )
  87. {
  88.     unsigned char buf[256];                /* ローカルワーク */
  89.     int    rc;
  90.     
  91.     /* Read Sub-Channel Command */
  92.     memset( buf, 0x00, 10 );
  93.     buf[0] = 0x42;                    /* Read Sub-Channel Command */
  94.     buf[1] = 0x02;                    /* Set MSF Bit */
  95.     buf[2] = 0x40;                    /* Set SubQ Bit */
  96.     buf[3] = 0x01;                    /* CD-ROM Current Posision */
  97.     buf[8] = 16;                    /* Allocation Length */
  98.  
  99.     if ( (rc=scsi_cmd( 10, buf, 16, buf2 ))!=0 )
  100.         if ( (rc=scsi_cmd( 10, buf, 16, buf2 ))!=0 )
  101.             rc=scsi_cmd( 10, buf, 16, buf2 );
  102.     return( rc );
  103.  
  104.  
  105. }
  106.  
  107. /* 曲数と最終演奏アドレスを求める */
  108. int RedTOC(int *leadout_address, int *min, int *max)
  109. {
  110.     unsigned char    buf[256];            /* ローカルワーク */
  111.     unsigned char    buf2[256];            /* ローカルワーク */
  112.     int    rc;
  113.  
  114.     /* Leadout Track Address get & Min. Max Track get */
  115.     memset( buf, 0x00, 10 );
  116.     buf[0] = 0x43;                    /* scsi2 ReadTOC Command */
  117.     buf[1] = 0x02;                    /* Set MSF Bit */
  118.     buf[6] = 0xaa;                    /* LeadoutOut Track */
  119.     buf[8] = 12;                    /* Allocation Length */
  120.  
  121.     if ( scsi_cmd( 10, buf, 12, buf2 )!=0 )
  122.         if ( scsi_cmd( 10, buf, 12, buf2 )!=0 )
  123.             if ( scsi_cmd( 10, buf, 12, buf2 )!=0 )
  124.                 return(-1);
  125.     *leadout_address = buf2[9] * 0x10000 + buf2[10] * 0x100 + buf2[11];
  126.     *min = buf2[2];                /* Min. Track */
  127.     *max = buf2[3];                /* Max. Track */
  128.     rc = 0;
  129.     return(rc);
  130. }
  131.  
  132. /* 演奏アドレスを求める */
  133. int Music_inf( int Track_no, int *start_address )
  134. {
  135.     unsigned char    buf[256];            /* ローカルワーク */
  136.     unsigned char    buf2[256];            /* ローカルワーク */
  137.     int    rc;
  138.  
  139.     /* Start Track Address  get */
  140.     memset( buf, 0x00, 10 );
  141.     buf[0] = 0x43;                    /* scsi2 ReadTOC Command */
  142.     buf[1] = 0x02;                    /* Set MSF Bit */
  143.     buf[6] = (unsigned char )Track_no;        /* Set Start Track */
  144.     buf[8] = 12;                    /* Allocation Length */
  145.  
  146.     if ( scsi_cmd( 10, buf, 12, buf2 )!=0 )
  147.         if ( scsi_cmd( 10, buf, 12, buf2 )!=0 )
  148.             if ( scsi_cmd( 10, buf, 12, buf2 )!=0 )
  149.                 return(-1);
  150.     *start_address = buf2[9] * 0x10000 + buf2[10] * 0x100 + buf2[11];
  151. /*    CTRL_ADDR = buf[5];    */        /* ADR/CTL 利用方法がわからん。*/
  152. #ifdef DEBUG1
  153.     printf(" CTL = %d\n",buf[5]);
  154. #endif
  155.     rc = 0;
  156.     return(rc);
  157. }
  158.  
  159. /* スピード変更コマンドを送る */
  160. int SetSpeed( int bps )
  161. {
  162.     unsigned char    com[256];            /* ローカルワーク */
  163.     unsigned char    buf[256];
  164.     int    r;
  165.     memset( com, 0x00, 12 );
  166.     com[0] = 0xbb;                    /* MMC / Set Speed Command */
  167.     com[2] = bps/0x100;
  168.     com[3] = bps&0xFF;
  169.     com[4] = 0xFF;                    /* 書き込み速度 */
  170.     com[5] = 0xFF;
  171.     r=scsi_cmd( 12, com, 0, buf );
  172.     if ( r==2 ){
  173.         S_REQUEST( 22, SCSI_ID, buf );        //dummy 発行
  174.         com[0] = 0xbb;                    /* MMC / Set Speed Command */
  175.         com[4] = 0x00;                    /* 書き込み速度 */
  176.         com[5] = 0x00;
  177.         r=scsi_cmd( 12, com, 0, buf );
  178.     }
  179.     return r;
  180. }
  181.